import "at3_cvmfs"
import "crvpuppet"

define at3_interactive($webaddr="", $roleid="") {
  if $AutoMode==true and $CloudCRV==true {
    $condorheadaddr=get_provider_attr($webaddr,$roleid,"CondorHeadAddr")
    $NFSServerClientMount=get_provider_attr($webaddr,$roleid,"NFSServerClientMount")
    $CondorPassword=get_role_attr($webaddr,$roleid,"CondorPassword")
  }

  notice("$condorheadaddr, $NFSServerClientMount")
  
  if ( $AutoMode == false ) or ( $AutoMode==true and $CloudCRV==true ) {
    package { "condor":
      ensure => installed,
    }

#    file { "$NFSServerClientMount/condor":
#      owner => "root",
#      group => "root",
#      ensure => directory,
#      mode => 755,
#    }
    
    file { "/etc/condor/condor_config":
      owner => "root",
      group => "root",
      ensure  => symlink,
      replace => true,
      target    => "$NFSServerClientMount/condor/condor_config",
      notify => Service["condor"],
    }
    
    file { "/etc/condor/condor_config.local":
      owner => "root",
      group => "root",
      mode => 644,
      content => template("at3_interactive/condor_config.local.tpl"),
      notify => Service["condor"],
    }
    
    exec { create_condorpassword:
      command => "condor_store_cred -c add -p $CondorPassword",
      require => File["/etc/condor/condor_config","/etc/condor/condor_config.local"],
      creates => "/var/condor_credentiald",
    }

    service { [ "condor"]:
      hasstatus => true,
      hasrestart => true,
      ensure => running,
      enable => true,
      require => [Package["condor"], Exec["create_condorpassword"]],
    }

  }
  
  if $AutoMode==true and $CloudCRV==true {
    #publish some variables, e.g. InteractiveNodePublicAddress and let CloudCRV display it on the front.
    set_role_attr($webaddr,$roleid,"ProfileApplied","True")
  }
}

define at3_interactive_reverse($webaddr, $roleid) {
  set_role_attr($webaddr,$roleid,"ReverseProfileApplied","True")
}

